package com.wzy.business.store.login

import android.os.Build
import android.view.WindowManager
import androidx.lifecycle.DefaultLifecycleObserver
import com.blankj.utilcode.util.ActivityUtils
import com.wangzhenyu.common.base.BaseActivity
import com.wangzhenyu.common.base.BasePreImpl
import com.wangzhenyu.common.base.BasePresenter
import com.wangzhenyu.common.base.bean.UserManager
import com.wangzhenyu.common.netcore.coroutine.CoroutineSupport
import com.wzy.business.R
import com.wzy.business.util.OtherUtils
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class BusinessActivity : BaseActivity<BasePresenter>() {

    private val mCoroutine: CoroutineSupport by lazy {
        CoroutineSupport()
    }

    override fun getLayoutId() = R.layout.business_activity_business

    override fun useBaseLayout() = false

    override fun createPresenter() = BasePreImpl(this)


    override fun initView() {

        //监听，为了onDestroy时取消
        lifecycle.addObserver(mCoroutine)

        //设置透明状态栏
        window.statusBarColor = android.R.attr.windowTranslucentStatus

        mCoroutine.launch {
            var againTime = 2
            while (againTime > 0) {
                againTime -= 1
                delay(250)
            }
            if (UserManager.isLogin()) {
                OtherUtils.goToMainActivity()
            } else {
                ActivityUtils.startActivity(LoginActivity::class.java)
            }
            finish()
        }

    }


}